#!/bin/bash

set -e

# Install target if not already installed
rustup target add aarch64-unknown-linux-musl

# Set the linker for aarch64-unknown-linux-musl
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc

# Build for aarch64-unknown-linux-musl target
cargo build --release --target aarch64-unknown-linux-musl

# Copy artifact to STARRY_BUILD
if [ -z "$STARRY_BUILD" ]; then
    echo "Error: STARRY_BUILD environment variable is not set"
    exit 1
fi

mkdir -p "$STARRY_BUILD"
cp target/aarch64-unknown-linux-musl/release/dino_terminal "$STARRY_BUILD/"

echo "Build complete. Artifact copied to $STARRY_BUILD/dino_terminal"

cd "${STARRY_BUILD}"
git add dino_terminal
git commit -m "Build dino_terminal for ${TARGET_TRIPLE}"
git push
